package com.thtfpc.utility;

import java.io.IOException;

public class InputUtil {
    public static interface InputListener {
        void onUserTypeString(String input);
    }

    public static void quitFor(String exitSign, InputListener callback) {
        byte[] bufferRead = new byte[256];
        try {
            int ret = 0;
            do {
                ret = System.in.read(bufferRead, 0, bufferRead.length);
                if (ret > 0) {
                    String inputString = new String(bufferRead, 0, ret);
                    if (inputString.equals(exitSign + "\n")) {
                        break;
                    }
                    else if (callback != null) {
                        callback.onUserTypeString(inputString.trim());
                    }
                }
            }
            while (ret > 0);
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
